﻿@using AntDesigner.GameCityBase
@model Account
@{
    Layout = "~/Views/Shared/_LayoutHaveManue.cshtml";
}
<h2>微信充值</h2>
<script>
    function jsApiCall()
    {
        WeixinJSBridge.invoke(
        'getBrandWCPayRequest',
      @Html.Raw(ViewBag.wxJsApiParam),//josn串
         function (res)
         {
             WeixinJSBridge.log(res.err_msg);
             if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                 frushPage();
             }
             else{
                 alert(res.err_code + res.err_desc + res.err_msg);
             }
         }
         );
    }

    function callpay()
    {
        if (typeof WeixinJSBridge == "undefined")
        {
            if (document.addEventListener)
            {
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            }
            else if (document.attachEvent)
            {
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        }
        else
        {
            jsApiCall();
        }
    }
    function frushPage()
    {
        alert("支付完成！");
        $("#accountBalance").html((parseFloat($("#accountBalance").html())+parseFloat($("#amount").text())).toFixed(2));
    }
</script>
<div class="text-center">
        账户余额
            <div id="accountBalance">@Model.Balance</div>
            <div>
                <br />
                @if (@ViewBag.wxJsApiParam == null)
                {

                    <form role="form" class="form-horizontal" action="/Player/creatOrder" method="post" onsubmit="return checkAmount()">
                        @Html.AntiForgeryToken()
                        <div class="form-group text-center">
                            <input type="text" class="form-control text-center " placeholder="在此输入充值金额" id="amount" pattern="^(([1-9]\d{0,9})|0)(\.\d{1,2})?$" name="amount" required />
                        </div>
                            <br />
                            <input class="btn btn-primary btn-lg btn-block text-center" value="确定" type="submit" />

                    </form>
                }
                else
                {
                    @:本次充值金额为:<span id="amount">@(ViewBag.Amount)</span><span>元</span>
                    <input class="btn btn-primary btn-lg btn-block text-center" type="button" value="立即用微信完成支付" onclick="callpay()" />
                }
             </div>
</div>
                <script>
    function checkAmount() {
        var redPackAmount = $("#amount").val()
         if (redPackAmount< 0.1) {
                        alert("不得低于0.1");
                        return false;
        }
        if (redPackAmount >50 ) {
            alert("根据禁止赌博的相关法规,每次最多充值50元");
            return false;
        }
        return true;
    }
                </script>

              